package com.woniu.controller;

import com.woniu.common.CommonResult;
import com.woniu.entity.CommunityActivity;
import com.woniu.service.CommunityActivityService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (CommunityActivity)表控制层
 *
 * @author makejava
 * @since 2020-03-29 21:49:13
 */
@RestController
@RequestMapping("/communityActivity")
public class CommunityActivityController {
    /**
     * 服务对象
     */
    @Resource
    private CommunityActivityService communityActivityService;

    /**
     * 功能描述: 查询最火的三条活动（根据参与人数判断，并且不为已经结束的活动）
     * @Param: []
     * @Return: com.woniu.common.CommonResult
     * @Author: yanghan
     * @Date: 2020/3/30 0:59
     */
    @GetMapping("/selectActivity")
    public CommonResult selectActivity(){
        try {
            List<CommunityActivity> activities = communityActivityService.selectActivity();
            return CommonResult.success(activities);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("查询活动失败");
        }
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public CommunityActivity selectOne(Integer id) {
        return this.communityActivityService.queryById(id);
    }

}